package com.junzhiit.nengji.api.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.api.service.AuthorizeService;
import com.junzhiit.nengji.api.service.SendPhoneService;
import com.junzhiit.nengji.api.web.util.aliyun.SmsUtil;
import com.junzhiit.nengji.api.web.vo.RegistVO;
import com.junzhiit.nengji.api.web.vo.RegisterBaseinfoVO;
import com.junzhiit.nengji.api.web.vo.RegisterShopVO;
import com.junzhiit.nengji.api.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
public class AuthorizeController extends BaseController{
	
	@Autowired
	private AuthorizeService authorizeService;
	
	@Autowired
	private SendPhoneService sendPhoneService;
	
	@ApiOperation(value="查询套餐（注册）")
	@RequestMapping(value = "/shop/register/get/setMeal",method = RequestMethod.GET)
	public ResultVO getRegisterSetMeal(){
		return authorizeService.getRegisterSetMeal();
	}
	
	@ApiOperation(value="查询免费套餐（注册）")
	@RequestMapping(value = "/shop/register/get/free/setMeal",method = RequestMethod.GET)
	public ResultVO getRegisterSetMealByFree(Integer isOpenFree){
		AssertUtil.notNull(isOpenFree, "isOpenFree is required.");
		return authorizeService.getRegisterSetMealByFree(isOpenFree);
	}
	
	@ApiOperation(value="商家注册-选择套餐")
	@RequestMapping(value = "/shop/register/setMeal",method = RequestMethod.POST)
	public ResultVO registerSetMeal(HttpServletRequest request,RegistVO registVO){
		AssertUtil.notBlank(registVO.getUserId(), "userId id is required.");
		AssertUtil.notBlank(registVO.getSetMealId(), "setMealId id is required.");
		AssertUtil.notBlank(registVO.getUserName(), "userName is required.");
		AssertUtil.notBlank(registVO.getMobilePhone(), "mobilePhone is required.");
		AssertUtil.notNull(registVO.getTradeType(), "tradeType is required.");
		return authorizeService.registerSetMeal(request,registVO);
	}
	
	@ApiOperation(value="商家注册-支付套餐失败")
	@RequestMapping(value = "/shop/register/pay/failure",method = RequestMethod.POST)
	public ResultVO registerSetMeal(String shopsLocatedId){
		AssertUtil.notBlank(shopsLocatedId, "shopsLocatedId id is required.");
		return authorizeService.registerPayFailure(shopsLocatedId);
	}
	
	@ApiOperation(value="获取手机验证码(注册)")
	@RequestMapping(value = "/get/mobile/phone/code", method = RequestMethod.GET)
	public ResultVO getMobilePhoneCode(String mobilePhone){
		AssertUtil.notBlank(mobilePhone, "mobile phone is required.");
		return sendPhoneService.sendPhoneCode(mobilePhone, SmsUtil.ALIYUN_SMS_TEMPLATE_CODE);
	}
	
	@ApiOperation(value="商家注册-基本信息")
	@RequestMapping(value = "/shop/register/baseinfo",method = RequestMethod.POST)
	public ResultVO register(RegisterBaseinfoVO registerBaseinfoVO){
		AssertUtil.notBlank(registerBaseinfoVO.getMobilePhone(), "mobilePhone token is required.");
		AssertUtil.notBlank(registerBaseinfoVO.getPassword(), "password token is required.");
		AssertUtil.notBlank(registerBaseinfoVO.getCode(), "code token is required.");
		AssertUtil.notBlank(registerBaseinfoVO.getName(), "name token is required.");
		AssertUtil.notBlank(registerBaseinfoVO.getEmail(), "email token is required.");
		AssertUtil.notBlank(registerBaseinfoVO.getShopsLocatedId(), "shopsLocatedId is required.");
		return authorizeService.register(registerBaseinfoVO);
	} 
	
	@ApiOperation(value="查询行业（注册）")
	@RequestMapping(value = "/shop/register/enregister/industry",method = RequestMethod.GET)
	public ResultVO registerEnregisterIndustry(){
		return authorizeService.registerIndustry(null);
	}	
	
	@ApiOperation(value="商家注册-创建店铺")
	@RequestMapping(value = "/shop/register/add",method = RequestMethod.POST)
	public ResultVO registerShopAdd(RegisterShopVO registerShopVO){
		AssertUtil.notBlank(registerShopVO.getSystemUserId(), "systemUserId is required.");
		AssertUtil.notBlank(registerShopVO.getShopsLocatedId(), "shopsLocatedId is required.");
		AssertUtil.notBlank(registerShopVO.getName(), "name is required.");
		AssertUtil.notBlank(registerShopVO.getMobilePhone(), "mobilePhone is required.");
		AssertUtil.notBlank(registerShopVO.getIndustryId(), "industryId is required.");
		AssertUtil.notNull(registerShopVO.getProfit(), "profit is required.");
		AssertUtil.notBlank(registerShopVO.getLinkman(), "linkman is required.");
		return authorizeService.registerShopAdd(registerShopVO);
	}
	
	@ApiOperation(value="商家注册-完善证件资料")
	@RequestMapping(value = "/shop/register/complet",method = RequestMethod.POST)
	public ResultVO registerComplet(RegisterShopVO registerShopVO){
		AssertUtil.notBlank(registerShopVO.getShopsLocatedId(), "shopsLocatedId is required.");
		AssertUtil.notBlank(registerShopVO.getShopInfoId(), "shopInfoId is required.");
		return authorizeService.registerComplet(registerShopVO);
	}
	
	@ApiOperation(value="检测用户入驻")
	@RequestMapping(value = "/shop/register/checked",method = RequestMethod.GET)
	public ResultVO registerEnregisterIndustry(String userId,String userCode){
		return authorizeService.registerChecked(userId,userCode);
	}	
}